import ccxt
import time
from datetime import datetime

api_key = "bOWuVDgNOF4nzUnRDkAqwHHotZfIeTCEp7Ml8c19usWtVSDYboDu3z2QYwwPJtFJ"
api_secret = "kqFeEFS3ZPmiiAu68aBzsUcHNJMJK9uBD86NFg8L21lQwVvIGUPz70yGQj0qVfHn"

# 初始化Binance交易所
exchange = ccxt.binance({
    'apiKey': api_key,
    'secret': api_secret,
})

exchange.load_markets()

# 定义交易对和金额
trades = [
    # {'symbol': 'ETHUSDT', 'amount': 0.01},
    #{'symbol': 'BTCUSDT', 'amount': 0.0005},
    #{'symbol': 'USDCUSDT', 'amount': 25},
    #{'symbol': 'FDUSDUSDT', 'amount': 25},

    # {'symbol': 'BNBUSDT', 'amount': 50},
    # {'symbol': 'ETHTRY', 'amount': 0.01},
    #{'symbol': 'USDTUAH', 'amount': 98},
    # {'symbol': 'ACMTRY', 'amount': 8.5},
    #{'symbol': 'USDTTRY', 'amount': 10},
    #{'symbol': 'USDTARS', 'amount': 17945},
    #{'symbol': 'USDTRON', 'amount': 20},
    # {'symbol': 'OMUSDT', 'amount': 10},
]

# 执行交易
for trade in trades:
    symbol = trade['symbol']
    amount = trade['amount']
    try:
        # 获取市场信息
        market = exchange.market(symbol)
        # 获取当前价格
        ticker = exchange.fetch_ticker(symbol)
        price = ticker['last']
        # 计算购买数量
        quantity = amount #/ price
        # 执行市价单
        order = exchange.create_market_buy_order(symbol, quantity)
        print(f"Successfully bought {quantity} {symbol} at market price.")
    except ccxt.BaseError as e:
        print(f"Failed to buy {symbol}: {e}")

# 再次获取账户余额
balance = exchange.fetch_balance()

# 打印交易后的各个币的数量
print("\nBalance after trades:")
for currency, info in balance['total'].items():
    if info > 0:
        print(f"{currency}: {info}")